<!-- subpkg_consult/department/index.vue -->
<script lang="ts" setup>
import { departmentListApi } from '@/apis/consult';
import type { DepartData } from '@/types/consult';
import { computed, ref } from 'vue';

// 1. 科室列表
const departmentList = ref<DepartData[]>([])
const getDepartmentList = async ()=>{
  const res = await departmentListApi()
  departmentList.value = res
}
getDepartmentList()
// 2. 切换选择
const activeIndex = ref(0)
const onChange = (i:number)=>{
  activeIndex.value = i
}

// 3. 获取二级科室
const subDepList = computed(() => departmentList.value[activeIndex.value]?.child)

defineProps<{
  type:string
  illnessType:string
}>()

</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <!-- 一级科室 -->
      <view v-for="(item,index) in departmentList" :key="item.id" class="department-item" @click="onChange(index)"
        :class="{ active: activeIndex ===index}">{{ item.name }}</view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator v-for="item in subDepList" :key="item.id" hover-class="none" :url="`/subpkg_consult/description/index?type=${type}&illnessType=${illnessType}&depId=${item.id}`"
        class="department-item">
        {{item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
@import './index.scss';
</style>